<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}
if (isset($_SESSION['lang']))
    $lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
    include "../value/value_en.php";
} else if ($lang == "VN") {
    include "../value/value_vn.php";
} else {
    include "../value/value_kr.php";
}

if (!isset($_SESSION['user']))
    header('Location: login.php?timeout=on');
else
    $id_employee = $_SESSION['IDEmployee'];

include '../operations/connection.php';
$kq = 0;
$money = str_replace(",", "", $_REQUEST['vMoney']);
$tmoney = $_REQUEST['tMoney'];
$trade = $_REQUEST['tTrade'];
//$time = $_REQUEST['time'];
$mNote = $_REQUEST['mNote'];
if ($trade == 0) {
    //mysql_query("UPDATE manage_money SET value=value+'$money' WHERE (`id`='$tmoney')");
    mysql_query("UPDATE manage_money SET value='$money' WHERE (`id`='$tmoney')");
    mysql_query("INSERT INTO log_manage_money (type_money,type_trade,value,time,note,id_employee) VALUES ('$tmoney', '$trade', '$money',NOW(),'$mNote','$id_employee')");
}
if ($trade == 1) {
    $q = mysql_query("SELECT m.value FROM manage_money m WHERE m.id='$tmoney';");

    $r = mysql_fetch_assoc($q);
    if ($r['value'] >= $money) {
        //mysql_query("UPDATE manage_money SET value=value-'$money' WHERE (`id`='$tmoney')");
        mysql_query("UPDATE manage_money SET value='$money' WHERE (`id`='$tmoney')");
        mysql_query("INSERT INTO log_manage_money (type_money,type_trade,value,time,note,id_employee) VALUES ('$tmoney', '$trade', '$money',NOW(),'$mNote','$id_employee')");
    } else {
        $kq = 1;
    }
}

$query = mysql_query("select * from manage_money");
$addressbrowser = $_SERVER['SERVER_NAME'];
$temp = explode(".", $addressbrowser);
?>
<input type="hidden" id="kq" value="<?= $kq ?>"/>
<table style="width:100%; padding-left:10px;">
<?php
while ($row = mysql_fetch_array($query)) {
    ?>
        <tr >
            <td  class="tdfirst"><?= $row['name' . $lang] ?></td>
            <td style="width: 260px"><input type="text" id="txttime" name="txttime" value="<?= number_format($row['value']) ?>" class="in_testfield" style="width:185px;float:left;height:33px;text-align: right;" readonly="readonly"/>  <p style="padding-left: 200px;">  VNĐ</p></td>
            <td></td>
        </tr>
<?php } ?>
    <tr>
        <td colspan="2" style="text-align: center;"><input style="margin:12px 5px 0 0; font-size: 12px;" type="button" value="<?= $l_sendmail ?>" onclick="sendmail('<?= $lang ?>','<?= $temp[0] ?>');"  class="btn_choose"  /></td>
        <td></td>
    </tr>
</table>
<?php mysql_close($connection); ?>						